home *** CD-ROM | disk | FTP | other *** search
- Path: gate.net!pslfl2-47
- From: bhutto@gate.net (William Hutto)
- Newsgroups: comp.lang.c
- Subject: Re: HELP! File Pointers
- Date: 9 Jan 1996 06:08:51 GMT
- Organization: CyberGate, Inc.
- Message-ID: <4ct0pj$19p2@news.gate.net>
- References: <4csr4c$fem@newsbf02.news.aol.com>
- NNTP-Posting-Host: pslfl2-29.gate.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4csr4c$fem@newsbf02.news.aol.com>,
- roberino@aol.com (Roberino) wrote:
- >I am currently trying to keep one file open while opening other
- >files one at a time using a separate file pointer. However, as
- >soon as I read a line from the second file, the first file pointer
- >somehow gets destroyed and set to some position in the newly
- >opened file. Has anyone else encountered this? And if so,
- >is there a solution? (i.e. A way to protect the first file pointer
- >from being overwritten.)
- >
- >Here are the steps I am performing:
- >
- >void main()
- ^^^^
- main() is the only function you *have* to return int.
-
- >{
- > FILE *File1;
- > FILE *File2;
- >
- > File1 = fopen("FILENAME", "r+");
- >
- > /* loop through lines in File1 using fgets() */
- >
- > if (Condition) /* just indicating some condition was met */
- > {
- > File2 = fopen("FILENAME2", "r+");
- >
- > fgets(Line, File2); <----- As soon as this occurs, File1 gets
- > wiped out. Why?
-
- I have to believe you're not including <stdio.h> or your compiler is not ANSI
- C compliant, otherwise you would certainly get an error. The declaration for
- fgets() is:
-
- char *fgets(char *string,int num,FILE *fileptr);
-
- Assuming Line is the string, you have left out the num value that limits the
- number of bytes (chars) read. fgets() will read characters up to and including
- a '\n' character or num-1 (whichever comes first) and append a '\0'. Make sure
- you include necessary header files so you don't have headeraches. :)
-
- You should also make sure that the FILE *'s are valid by comparing them to
- NULL before using them.
-
-
- > }
-
- Throw in a:
- return 0;
- here.
-
- >}
- >
- >Please send any and all replies through email to
- > roberino@aol.com.
- >I appreciate any and all help.
- >
- >Thank you,
- >Rob
-
-
- Bill
-
- "Whatcha got on?...Your mind?"
-